<?php
namespace app\admin\validate;

use think\Validate;

/**
 * 轮播图验证器
 * Class Slide
 * @package app\admin\validate
 */
class Ad extends Validate
{
    protected $rule = [
        'posid'  => 'require',
        'name' => 'require',
        'image' => 'require',
        'link' => 'require|is_url:1',
        'sort' => 'require|number|max:255'
    ];

    protected $message = [
        'posid.require'  => '请选择所属分类',
        'name.require' => '请输入名称',
        'image.require' => '请上传图片',
        'link.require' => '请输入链接',
        'sort.require'  => '请输入排序',
        'sort.number'  => '排序只能填写数字',
        'sort.max'  => '排序最大数字255'
    ];
    
    protected function is_url($value){
    	$exp = "/^(https?:\/\/)?(((www\.)?[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)?\.([a-zA-Z]+))|(([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5])\.([0-1]?[0-9]?[0-9]|2[0-5][0-5]))(\:\d{0,4})?)(\/[\w- .\/?%&=]*)?$/i";  
        if(preg_match($exp,$value)){  
            return true;  
        }else{  
            return '链接格式不正确';  
        }  
    }
}